﻿#include "FITKMeshGenGmshExecInterface.h"
#include "FITKMeshGenerateProcessorGmshExec.h"
#include "FITKMeshSizeGeneratorGmshExec.h"
#include "FITKMeshAlgorithmGeneratorGmshExec.h"
#include "FITKMesherDriverGmshExec.h"
#include "FITK_Interface/FITKInterfaceMeshGen/FITKMeshGenInterface.h"
#include "FITK_Kernel/FITKCore/FITKDirFileTools.h"
#include <QApplication>
#include <QFile>

namespace Gmsh
{
    FITKMeshGenGmshExecInterface::FITKMeshGenGmshExecInterface()
    {
        //拷贝文件
        QString gmshExecPath = QApplication::applicationDirPath() + QString("/gmsh");
        if(Core::CreateDir(gmshExecPath))
        {
            //拷贝gmsh.exe
            QString gmshExeFile = gmshExecPath + QString("/gmsh.exe");
            if (!QFile::exists(gmshExeFile))
            {
                qWarning("FITKMeshGenGmshExecInterface: Copy gmsh.exe to %s", qPrintable(gmshExeFile));
            }
            //拷贝License.txt
            QString licenseFile = gmshExecPath + QString("/License.txt");
            if (!QFile::exists(licenseFile))
            {
                QFile::copy("://gmsh/License.txt", licenseFile);
            }
        }
        else
        {
            qWarning("FITKMeshGenGmshExecInterface: Failed to create directory %s", qPrintable(gmshExecPath));
        }
        

        //获取工厂
        Interface::FITKMeshGenInterface* mf = Interface::FITKMeshGenInterface::getInstance();
        if (nullptr == mf) return;
        //注册相关类
        mf->regMeshSizeGenerator(new FITKMeshSizeGeneratorGmshExec, "GmshExec");
        mf->regMesherDriver(new FITKMesherDriverGmshExec, "GmshExec");
        mf->regMeshProcessor(new FITKMeshGenerateProcessorGmshExec, "GmshExec");
        mf->regMeshAlgorithmGenerator(new FITKMeshAlgorithmGeneratorGmshExec, "GmshExec");
    }


    QString FITKMeshGenGmshExecInterface::getComponentName()
    {
        //名称
        return QString("FITKMeshGenGmshExec");
    }

    bool FITKMeshGenGmshExecInterface::exec(const int indexPort)
    {
        return false;
    }


}



